package tw.twandroidproj.app.ui.Apply;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tw.twandroidproj.app.R;

/**
 * Created by ZRP on 2016/5/21.
 */
public class jobApply_timeAdapter extends RecyclerView.Adapter<jobApply_timeAdapter.ViewHolder> {

    private Context jobApplyContext;
    public List<String> jobApply_Time = new ArrayList<String>();

    public jobApply_timeAdapter(Context context){
        jobApply_Time.add("5/26至5/27（8：00至10：00）");
        jobApplyContext = context;
        Log.i("适配器","构造函数");
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(jobApplyContext).inflate(R.layout.select_jobtime_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.jobApply_timeText.setText(jobApply_Time.get(position));
        holder.jobApply_cImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                remove(position);
            }
        });
    }


    @Override
    public int getItemCount() {
        return jobApply_Time.size();
    }

    public void remove(int position) {
        jobApply_Time.remove(position);
        notifyItemRemoved(position);
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView jobApply_timeText;
        ImageView jobApply_cImage;

        public ViewHolder(View itemView) {
            super(itemView);
            jobApply_timeText=(TextView)itemView.findViewById(R.id.jobApply_timeText);
            jobApply_cImage  = (ImageView) itemView.findViewById(R.id.jobApply_cImage);
        }
    }
}
